<template>
	<view>
		<view class="page_bg">
			<image class="bg_img" src="../static/youhuiquan.jpg" mode="aspectFill"></image>
		</view>
		<view class="option_main">
			<view class="en_bg">
				<image class="en_bg_img" mode="" src="../static/youhuiquancenter.png"></image>
				<view class="price_box">
					<text class="num">{{ $price(dataForm.price) }}</text>
					<text class="sign u-font-40">元</text>
				</view>
				<view class="open_top">
					<view class="condition">满{{ $price(dataForm.full_reduce) }}元可用</view>
					<view class="en_title u-p-t-10">
						<view class="title_txt u-line-1 u-font-28">{{ dataForm.name }}</view>
					</view>
					<view class="en_title" v-if="dataForm.remark" >
						<view class="title_txt u-line-1 u-font-28">{{ dataForm.remark }}</view>
					</view>
					<view :class="['time',dataForm.remark?'u-p-t-10':'u-p-t-40']">
						到期：{{ (dataForm.coupon_receive_status == 1 ? dataForm.coupon_receive_effective : dataForm.end_effective) | formatTime }}
					</view>
				</view>
				<view class="open_bot">
					<view class="btn" @click="optionEnve">
						<image class="btn-img" src="../static/btn.png" mode=""></image>
						<text class="text">{{ dataForm.coupon_receive_status == 1 ? '去使用' : '立即领取' }}</text>
					</view>
				</view>
			</view>
		</view>
		<sww-login></sww-login>
	</view>
</template>

<script>
	import {
		formatDate
	} from '@/utils/moment/index.js';
	export default {
		data() {
			return {
				coupon_id: '',
				user_id: '',
				coupon_receive_id: '',
				dataForm: {},
				envelopeVisible: false
			}
		},
		filters: {
			formatTime(val) {
				return formatDate(val, 'YYYY-MM-DD HH:mm:ss');
			}
		},
		onLoad(option) {
			this.coupon_id = option.id
			this.user_id = option.user_id
			this.coupon_receive_id = option.coupon_receive_id
			this.initPage()
		},
		methods: {
			initPage() {
				this.$resPost('GetCouponInfo', {
					pk_id: this.coupon_id,
					users_id: this.vuex_user.pk_id
				}).then(({
					data
				}) => {
					this.dataForm = data
					if (this.user_id == this.vuex_user.pk_id) {
						this.$toast('不能自己领取');
						setTimeout(() => {
							this.$linkTo('index')
						}, 1000)
						return
					}
				})
			},
			optionEnve() {
				if (this.dataForm.coupon_receive_status == 1) return

				this.$resPost('TransferCoupon', {
					coupon_id: this.coupon_receive_id,
					users_id: this.vuex_user.pk_id
				}).then(res => {
					this.$toast('领取成功');
					setTimeout(() => {
						this.$linkTo('index')
					}, 1000)
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.page_bg {
		padding-bottom: 64%;
		position: relative;

		.bg_img {
			position: absolute;
			left: 0;
			top: 0;
			width: 100%;
			height: 100vh;
		}
	}

	.option_main {
		margin-top: -56rpx;
		text-align: center;
		position: relative;
		z-index: 10;

		

		.record_tip {
			font-size: 30rpx;
			text-decoration: underline;
			color: #ff0140;
			margin: 40rpx 0;
		}
	}

	.en_bg {
		width: 690rpx;
		height: 700rpx;
		position: relative;
		margin: 0 auto;

		.en_bg_img {
			width: 100%;
			height: 100%;
			position: absolute;
			top: 0;
			left: 0;
		}

		.price_box {
			position: absolute;
			color: #f60f0b;
			text-align: center;
			top: 220rpx;
			left: 110rpx;

			.num {
				font-size: 90rpx;
			}

			.sign {
				padding-left: 6rpx;
			}
		}

		.open_top {
			position: absolute;
			top:210rpx;
			right: 70rpx;
			.en_title {
				display: flex;

				.title_txt {
					color: #ff444b;
					max-width: 100%;
				}
			}

			.open_prod {
				background-color: #fff;
				border-radius: 10rpx;
				padding: 10rpx;
				display: flex;
				margin-top: 30rpx;

				.prod_img {
					margin-right: 16rpx;
					width: 106rpx;
					height: 106rpx;
				}

				.prod_cont {
					color: #e52e4d;

					.prod_name {
						font-size: 28rpx;
					}
				}
			}
			.time {
				color: #f60f0b;
				font-size: 24rpx;
				text-align: left;
				line-height: 30rpx;
			}


			.condition {
				text-align: left;
				font-weight: bold;
				color: #f60f0b;
				font-size: 40rpx;
			}
		}

		.open_bot {
			position: absolute;
			bottom: 0;
			left: 0;
			width: 100%;
			padding-bottom: 64rpx;
			.btn {
				margin: 0 auto;
				height: 90rpx;
				display: flex;
				align-items: center;
				justify-content: center;
				width: 288rpx;
				position: relative;
				.btn-img{
					position: absolute;
					width: 100%;
					height: 120rpx;
				}
				.text{
					font-size: 34rpx;
					color: #ff444b;
					font-family: Alibaba PuHuiTi;
					font-weight: bold;
					z-index: 1;
				}
			}
		}
	}
</style>
